Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
postcss-values-parser
Advanced tools
The postcss-values-parser package is a tool for parsing CSS values, allowing developers to analyze and manipulate CSS strings in JavaScript. It provides a detailed AST (Abstract Syntax Tree) for CSS values, making it easier to understand and modify CSS properties programmatically.
Parsing CSS values
This feature allows you to parse any string representing CSS values into a structured AST. The code sample demonstrates parsing a simple CSS value string.
const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
console.log(root.nodes);
Walking through the AST
After parsing CSS values into an AST, this feature enables walking through the AST nodes. This can be useful for analyzing or modifying specific parts of the CSS value.
const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
root.walk((node) => console.log(node));
Modifying CSS values
This feature demonstrates how to modify CSS values after parsing. In the code sample, the size value of a CSS property is changed from '10px' to '15px'.
const parse = require('postcss-values-parser').parse;
let root = parse('10px solid black');
root.nodes[0].value = '15px';
console.log(root.toString());
css-tree is a CSS parser that produces an AST for CSS documents. It offers similar functionality for parsing CSS but is more focused on entire stylesheets rather than individual values. Compared to postcss-values-parser, css-tree provides a broader scope of CSS parsing capabilities.
css-what is a package for parsing CSS selectors. It provides functionality to parse selector strings into an understandable format but does not focus on CSS properties or values. While it offers parsing capabilities, its focus is different from that of postcss-values-parser, which is more centered on CSS values.
A CSS property value parser built upon PostCSS, following the same node and traversal patterns as PostCSS.
Using npm:
npm install postcss-values-parser --save-dev
Please consider becoming a patron if you find this module useful.
postcss-values-parser
Node version v6.14.0+ and PostCSS v7.0.0+.
Using the parser is straightforward and minimalistic:
const { parse } = require('postcss-values-parser');
const root = parse('#fff');
const node = root.first;
// → Word {
// raws: { before: '', after: '' },
// value: '#fff',
// type: 'word',
// isHex: true,
// isColor: true,
// isVariable: false,
// ...
// }
Please see the Documentation for further information on using the module.
FAQs
A CSS property value parser for use with PostCSS
The npm package postcss-values-parser receives a total of 1,395,100 weekly downloads. As such, postcss-values-parser popularity was classified as popular.
We found that postcss-values-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.